<?php
	require_once('inc/config.php');
	if (!isset($_FILES['Filedata']) || $_FILES['Filedata']['error'] != UPLOAD_ERR_OK) {
		die('{result: false; error: "Couldn\'t upload"}');
	}
	$ext = substr($_FILES['Filedata']['name'], strrpos($_FILES['Filedata']['name'], '.') + 1);
	switch ($ext) {
		case "png":
		case "gif":
		case "jpg":
			//all ok
		break;
		default:
			die('{result: false; error: "Invalid extension!"}');
	}
	//iconv("UTF-8", "cp1251", $_FILES['Filedata']['name'])
	move_uploaded_file($_FILES['Filedata']['tmp_name'], $config['upload_dir'].'/'.$_FILES['Filedata']['name']);
	$error = error_get_last();
	if ($error['type'] == E_ERROR || $error['type'] == E_WARNING) {
		die('{result: false; error: "Couldn\'t copy."}');
	}
	echo('{result: true;');
	ob_start();
	//phpinfo();
	print_r($_FILES);
	print_r($_POST);
	$request = ob_get_clean();
	$file = fopen("reqlog.log", "a");
	fwrite($file, $request);
	fclose($file);
?>